import java.util.Scanner;
public class array {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("请输入数组长度: ");
        int length = scanner.nextInt();

        int[] arr = new int[length];

        // 输入数组元素
        for (int i = 0; i < length; i++) {
            System.out.print("请输入第 " + (i + 1) + " 个元素: ");
            arr[i] = scanner.nextInt();
        }

        // 打印数组元素个数
        System.out.println("数组元素个数为: " + arr.length);

        // 打印数组元素
        System.out.print("数组元素为: ");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println(); // 换行

        // 实现数组赋值功能
        System.out.print("请输入要赋值的索引: ");
        int index = scanner.nextInt();

        if (index >= 0 && index < arr.length) {
            System.out.print("请输入新的值: ");
            int newValue = scanner.nextInt();
            arr[index] = newValue;
            System.out.println("数组元素已成功赋值");
        } else {
            System.out.println("错误：索引超出数组范围");
        }

        // 打印更新后的数组元素
        System.out.print("更新后的数组元素为: ");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println(); // 换行

        scanner.close();
    }
}
